package com.ucode.hrm.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjUtil;
import com.ucode.hrm.mapper.HrmLeaveApplyRecordMapper;
import com.ucode.hrm.service.HrmLeaveApplyRecordService;
import com.ucode.model.hrm.HrmLeaveApplyRecord;
import com.ucode.tool.base.enums.CommonAuditStatusEnum;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class HrmLeaveApplyRecordServiceImpl implements HrmLeaveApplyRecordService {

    @Resource
    private HrmLeaveApplyRecordMapper leaveApplyRecordMapper;

    @Override
    public HrmLeaveApplyRecordMapper initMapper() {
        return leaveApplyRecordMapper;
    }


    @Override
    public void audit(Long id, Integer auditStatus, Long processorId, String processRemark) {
        HrmLeaveApplyRecord bean = leaveApplyRecordMapper.selectByPrimaryKey(id);
        if(bean.getDeltag() || !ObjUtil.equals(bean.getAuditStatus(), CommonAuditStatusEnum.SUBMIT_REVIEW.getCode())) {
            return;
        }

        HrmLeaveApplyRecord updateBean = new HrmLeaveApplyRecord();
        updateBean.setId(id);
        updateBean.setAuditStatus(auditStatus);
        updateBean.setProcessRemark(processRemark);
        updateBean.setProcessorId(processorId);
        updateBean.setProcessTime(LocalDateTimeUtil.now());

        leaveApplyRecordMapper.update(updateBean);
    }
}
